<?php
// TODO this should run virtual browser with javascript engine over all found index.html files and record any errors

function listFiles( $from = '.', $ext)
{
    if(! is_dir($from))
        return false;
   
    $files = array();
    $dirs = array( $from);
    while( NULL !== ($dir = array_pop( $dirs)))
    {
        if( $dh = opendir($dir))
        {
            while( false !== ($file = readdir($dh)))
            {
                if( $file == '.' || $file == '..')
                    continue;
                $path = $dir . '/' . $file;
                if( is_dir($path))
                    $dirs[] = $path;
                else
				if(strrpos($path, $ext) !== false && strrpos($path, ".svn") === false)
                    $files[] = $path;
            }
            closedir($dh);
        }
    }
    return $files;
}

function listTests()
{
	echo "<ul>";
	$dir = dirname(__FILE__);
	$tests = listFiles($dir, ".html");
	foreach($tests as $test)
	{
		$test = str_replace($_SERVER["DOCUMENT_ROOT"].'test/', "", $test);
		echo "<li> <a href='$test'> $test </a> </li>";
	}
	echo "</ul>";
}

?>
<html>
	<body>
		<?php listTests(); ?>
	</body>
</html>
